package com.dcy.daily.skill.jvm.memoryAlloc.toolsOfJvm;

import java.util.ArrayList;

/**
 * Java监视与管理控制台，对应Jvm书P157,是可视化监视、管理工具。
 * 包括概述、内存监控、线程监控。该示例展示了内存监控。在JDK/bin运行JConsole.exe
 *
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年06月02日 20:34:00
 */
public class JConsole_MemoryMonitorUsage {
    static class OOMObject{
        public byte[] placeholder = new byte[64 * 1024];
    }

    public static void fillHeap(int num) throws InterruptedException{
        ArrayList<OOMObject> list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            Thread.sleep(50);
            list.add(new OOMObject());
        }
        System.gc();
    }

    /**
     * Jvm参数：-Xms100m -Xmx100m -XX:+UseSerialGC
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        fillHeap(1000);
    }
}
